/*
echo 服务端 udp 实现。测试 udp 缺乏流量控制。
**/

#include "dg_echo.h"
#include <define.h>
#include <error.h>
#include <wrapfunc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>


int
main() {
	struct sockaddr_in localaddr;
	memset(&localaddr, 0, sizeof(localaddr));
	localaddr.sin_family = AF_INET;
	localaddr.sin_port = htons(SERV_PORT);
	localaddr.sin_addr.s_addr = htonl(INADDR_ANY);

	int sockfd = Socket(AF_INET, SOCK_DGRAM, 0);
	Bind(sockfd, (struct sockaddr*)&localaddr, sizeof(localaddr));

    // 运行服务端前后执行 netstat -su 查看统计，关注 packets received 这行查看丢失的数据
	struct sockaddr_in addr;
	dg_echoloop1(sockfd, (struct sockaddr*)&addr, sizeof(addr));

	Close(sockfd);
	return 0;
}
